home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ham Radio 2000
/
Ham Radio 2000.iso
/
ham2000
/
packet
/
monax25
/
sparse.c
< prev
next >
Wrap
Text File
|
1987-10-20
|
9KB
|
432 lines
/* sparse.c - Parser for STATS tool.
This module is part of stats.exe
Language = Microsoft C version 4.0
This source is distributed freely and may be copied and
redistributed with the following provisos:
You may not sell it, nor may you charge for making
copies beyond the actual cost of mailing and media.
Written by Skip Hansen WB6YMH and Harold Price NK6K.
Feedback is desired.
RCP/M (213) 541-2503 300/1200/2400 baud
or via packet WB6YMH @ WB6YMH-2 or
NK6K @ NK6K
Modification history:
8/10/87 NK6K: Initial release.
ver 1.0
10/18/87 NK6K: First general release.
ver 1.1
Notes: This was a quick grab from something else that was
laying around, and has several hooks for things
which aren't actually here. On the other hand, it
does the job. To add new commands, add the text to
sparse.h and a new case in doit() below.
*/
#include "sparse.h"
#include <ctype.h>
#include <stdio.h>
#include <dos.h>
#define FALSE 0
#define TRUE !FALSE
/* common variables */
extern int p_timestamp;
extern int p_baud;
extern int p_port;
extern int port_base;
char using_combios;
char ints_active;
#define promptlen 4;
#define WAIT 1
int ars,point,ppoint,i,tc;
unsigned int pnum;
int old_more;
char token[129];
char buf[128];
int ctype;
int ltype;
int first_com_g;
int tflag,ok,eh;
#define true 1
#define false 0
int point;
enum ttypes { notoken,
alftoken,
numtoken,
qmarktoken, /* ? */
cmarktoken, /* ; */
qtmarktoken, /* " */
errtoken} typtoken;
char oplist[] = " ?;\"";
FILE *fin, *fout, *fopen();
int in_open = 0;
int out_open = 0;
union REGS inregs, outregs;
int baud[] = {
110,150,300,600,1200,2400,4800,9600};
int sp_skip(i)
int i;
{
int looping;
looping = true;
point = i;
while (looping) {
if (point >=ars) looping = false;
else if(buf[point]==' ') point++;
else looping = false;
}
return(point<ars);
}
ptoken(npoint)
int npoint;
{
int i,looping,itemp;
char c;
memset(token,' ',127);
looping = sp_skip(npoint);
ppoint = point;
pnum = 0;
tc = -1;
typtoken = notoken;
/* get token first */
/* check for opcodes */
if (looping) {
typtoken=errtoken; /* once started, it isn't notoken */
c = buf[point];
if(c=='?') {
tc++;
point++;
looping = false;
typtoken=qmarktoken;
}
else if(c==';') {
tc++;
point++;
looping = false;
typtoken=cmarktoken;
}
else if(c=='"') {
point++;
looping = true; /* keep looping */
typtoken=qtmarktoken;
}
}
if (!looping) token[tc]=c; /* opcode */
if (typtoken==qtmarktoken) {
/* quoted string */
while (looping) {
c = buf[point];
if (c=='"') { /* check for double delimiter */
if (point+1>=ars) {
looping=false;
point++; /* skip past ' */
}
else if (buf[point+1]=='"') { /* put a ' into the token */
tc++;
if (tc<127) token[tc] = c;
point+=2; /* skip past both ' */
}
else {
looping=false;
point++; /* skip past closing ' */
}
}
else {
tc++;
if (tc<127) token[tc] = c;
point++;
if (point>=ars) {
looping = false;
typtoken=errtoken; /* no trailing ' */
}
}
} /* while looping */
} /* end if qtmark */
else if (looping) {
/* alphanumeric token */
typtoken=alftoken;
while (looping) {
c = buf[point];
if ((isalnum(c)) || (c=='_') || (c=='.') || (c=='-') ||
(c=='/')||(c=='\\')) {
tc++;
if (tc<127) token[tc] = c;
point++;
if (point>=ars) looping = false;
}
else if (NULL==strchr(oplist,c)) {
looping = false;
typtoken=errtoken;
}
else looping = false;
}
}
token[tc+1]='\0';
/* now characterize it */
if (typtoken==alftoken) { /* alphanumeric, check for numeric */
typtoken = numtoken;
for (i=0;i<tc;i++) {
if (!isdigit(token[i])) {
typtoken=alftoken;
break;
}
}
}
/* convert numeric tokens */
pnum=0;
if (typtoken==numtoken)
for(i=0;i<=tc;i++) pnum = pnum*10 + token[i]-'0';
}
pcom()
{
int match, looking, i;
looking = true;
ctype = 1+ (int) c_fnull ;
while (comtext[ctype].c[0]!='\0' && (looking==1)) {
match = true;
i = 0;
while ((i <= tc) && (match==1)) {
match = (toupper(token[i]) == comtext[ctype].c[i]);
i++;
}
if (match==1) looking = false;
else ctype++;
}
}
writedol(i)
int i;
{
int j;
i = i + promptlen;
for (j=0;j<i;j++) cprintf(" ");
cprintf("^");
}
writeeh(i)
int i;
{
writedol(i);
cprintf(" Error");
pbreak();
}
peh()
{
eh=true;
ok=false;
}
doit()
{
int i,j,k,ii;
unsigned int pnumt;
char com_out[255];
unsigned char cmdnum, cmdtask;
unsigned int com_out_l;
switch (ctype) {
case c_lnull:
ok = false;
eh = true;
break;
case c_help:
ptoken(point);
printf("Commands are:\n");
i=(numcom)/8;
k=1;
for (j=0;j<i;j++) {
for (ii=0;ii<8;ii++,k++) printf("%.8s ",comtext[k].c);
printf("\n");
}
for (ii=0;ii<((numcom) % 8);ii++,k++)
printf("%.8s ",comtext[k].c);
printf("\n");
break;
case c_baud:
ptoken(point);
if (typtoken==notoken)
printf("Baud rate is %u\n",p_baud);
else if (typtoken!=numtoken) peh();
else{
for(i = 0; i < 8; i++){
if(pnum == baud[i])
break;
}
if(i == 8){
printf("Error: Baudrate %d is not supported.\n",pnum);
break;
}
if(using_combios){
/* set up port for 8 bits, 1 stop, no parity */
inregs.h.al = (i << 5) + 3;
inregs.h.ah = 0; /* Initialize */
inregs.x.dx = p_port;
int86(0x14,&inregs,&outregs);
}
else{
serlbaud(p_port,i);
}
p_baud = pnum;
}
break;
case c_port:
ptoken(point);
if (typtoken==numtoken) {
/* check for supported COM port */
inregs.h.ah = 4; /* Inquiry */
inregs.x.dx = pnum;
int86(0x14,&inregs,&outregs);
if(outregs.x.ax == 0xaa55){
if(ints_active)
serldone();
ints_active = FALSE;
using_combios = TRUE;
p_port = pnum;
break;
}
else if(pnum == 0 || pnum == 1) {
if(ints_active)
serldone();
serlinit(pnum);
ints_active = TRUE;
using_combios = FALSE;
p_port = pnum;
/* reset base adr for CD sampler */
if(p_port){
set_base(0x2f8); /* com2 */
}
else{
set_base(0x3f8); /* com1 */
}
break;
}
else{
printf("Error: Invalid or unsupported port number %d.\n",pnum);
}
}
else if (typtoken!=notoken) {
peh();
break;
}
printf ("Port is %u (COM%u)\n",p_port,p_port+1);
break;
case c_end:
case c_quit:
serldone();
tick_stop();
dump_data();
exit(0);
break;
case c_time:
p_timestamp = !p_timestamp;
if (p_timestamp) printf("Screen timestamping is now on\n");
else printf("Screen timestamping is now off\n");
break;
case c_base:
ptoken(point);
if (typtoken==numtoken) {
port_base = pnum;
set_base(port_base);
}
else if (typtoken!=notoken) {
peh();
break;
}
printf ("Port base address is %Xh\n",port_base);
break;
default:
cprintf("*** internal error, parser default case\n");
break;
}
if(typtoken==cmarktoken) point--;
}
parse(flag,s)
int flag; /* command line flag */
char *s;
{
ok = true;
eh = false;
if (flag)
strcpy (buf,s);
else gets(buf);
ars = strlen(buf);
ptoken(0);
while ((ok) && (typtoken!=notoken)){
if (typtoken==qmarktoken) {
ctype=(int) c_help;
doit();
}
else if ((typtoken==alftoken)||(typtoken==numtoken)) {
pcom();
if (ctype == (int) c_lnull) {
ok = false;
eh = true;
}
else doit();
}
else if (typtoken==cmarktoken) ; /* do nothing */
else {
ok = false;
eh = true;
}
if (ok) ptoken(point);
else if (eh) writeeh(ppoint);
}
}
pbreak()
{
cprintf("\r\n");
}